package com.rssreader.client;

import com.extjs.gxt.ui.client.Registry;
import com.extjs.gxt.ui.client.mvc.Dispatcher;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.rssreader.client.mvc.controllers.PortalController;
import com.rssreader.client.portlets.ChartPortlet;
import com.rssreader.client.portlets.FeedPortlet;
import com.rssreader.client.portlets.ItemPortlet;
import com.rssreader.client.portlets.NavPortlet;
import com.rssreader.client.portlets.OverviewPortlet;
import com.rssreader.client.services.FeedService;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class RSSReader implements EntryPoint {

    @Override
    public void onModuleLoad() {
	// 通過FeedService.class，得到了FeedServiceAsync.class
	Registry.register(RSSReaderConstants.FEED_SERVICE,
		GWT.create(FeedService.class));

	// 檢索Dispatcher實體
	Dispatcher dispatcher = Dispatcher.get();

	// Controller向Dispatcher註冊
	// dispatcher.addController(new AppController());
	// dispatcher.addController(new NavController());
	// dispatcher.addController(new FeedController());
	// dispatcher.addController(new ItemController());
	// dispatcher.addController(new StatusController());

	// 雖然只執行一次派發Init事件，但會派發到各Controller去，因為App, Nav,
	// FeedController都註冊了Init，執行的順序是跟上方Dispatcher增加Cotroller的順序有關
	// dispatcher.dispatch(AppEvents.Init);
	// dispatcher.dispatch(AppEvents.UIReady);

	dispatcher.addController(new PortalController());
	// 非直接派發事件，因在NavPortlet類別中，才派發事件
	new NavPortlet();
	new OverviewPortlet();
	new FeedPortlet();
	new ItemPortlet();
	new ChartPortlet();
    }
}
